
const db = require('../config/db')
function number(role) {
    // 查询用户表
    let jobnumber;
    switch (role) {
        case 'admin':
            jobnumber = 'A'
            break;
        case 'doctor':
            jobnumber = 'B'
            break;
        case 'nurse':
            jobnumber = 'C'
            break;
    }
    return new Promise((resolve, reject) => {
        let user_check_sql = 'select * from user where role = "' + role + '"';
        db.query(user_check_sql, (err, rows) => {
            if (err) {
                res.send({
                    code: -1,
                    msg: '查询失败'
                });
            } else {
                // 解构赋值(数据库)
                if (rows && rows.length != 0) {
                    console.log(rows);
                    jobnumber = jobnumber + (Number(rows[rows.length-1].jobnumber.replace(/[^0-9]/ig, '')) + 1);
                } else {
                    jobnumber = jobnumber + 0;
                }
                resolve(jobnumber)
            }
        })
    })

}
module.exports = number;